package com.example.phone.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.BDNotifyListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.map.LocationData;
import com.baidu.mapapi.map.MKMapViewListener;
import com.baidu.mapapi.map.MapController;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MyLocationOverlay;
import com.baidu.platform.comapi.basestruct.GeoPoint;

public class TabHostActivity extends TabActivity implements
		OnCheckedChangeListener {
	/** Called when the activity is first created. */

	//private LocationClient mLocationClient;
	//public BDLocationListener myListener = new MyLocationListener();
	private RadioGroup group;
	private TabHost tabHost;
	public static final String TAB_ITEM_1 = "tabItem1";

	public static final String TAB_ITEM_2 = "tabItem2";

	public static final String TAB_ITEM_3 = "tabItem3";

	public static final String TAB_ITEM_4 = "tabItem4";
	public static final String TAB_ITEM_5 = "tabItem5";
	
	public LocationOverlayDemo locationOverlayDemo;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tabhost);

		//mLocationClient = new LocationClient(getApplicationContext());     //声明LocationClient类
	   //mLocationClient.registerLocationListener( myListener );    //注册监听函数
	    
		group = (RadioGroup) findViewById(R.id.main_radio);
		group.setOnCheckedChangeListener(TabHostActivity.this);

		//mLocationClient = new LocationClient(getApplicationContext()); 
		
		tabHost = this.getTabHost();
		TabSpec tab1 = tabHost.newTabSpec(TAB_ITEM_1);
		TabSpec tab2 = tabHost.newTabSpec(TAB_ITEM_2);
		TabSpec tab3 = tabHost.newTabSpec(TAB_ITEM_3);
		TabSpec tab4 = tabHost.newTabSpec(TAB_ITEM_4);
		TabSpec tab5 = tabHost.newTabSpec(TAB_ITEM_5);

		tab1.setIndicator(TAB_ITEM_1).setContent(
				new Intent(this, PictureShowActivity.class));
		tab2.setIndicator(TAB_ITEM_2).setContent(
				new Intent(this, PictureShowActivity.class));
		tab3.setIndicator(TAB_ITEM_3).setContent(
				new Intent(this, ListBusActivity.class));
		tab4.setIndicator(TAB_ITEM_4).setContent(
				new Intent(this, SeekActivity.class));
		tab5.setIndicator(TAB_ITEM_5).setContent(
				new Intent(this, LoginActivity.class));

		tabHost.addTab(tab1);
		tabHost.addTab(tab2);
		tabHost.addTab(tab3);
		tabHost.addTab(tab4);
		tabHost.addTab(tab5);
		group.check(R.id.radio_button1);
		tabHost.setCurrentTabByTag(TAB_ITEM_1);

	}

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		// TODO Auto-generated method stub

		switch (checkedId) {

		case R.id.radio_button1:
			tabHost.setCurrentTabByTag(TAB_ITEM_1);
			break;
		case R.id.radio_button2:
			tabHost.setCurrentTabByTag(TAB_ITEM_2);
			Intent intent5 = new Intent();
			intent5.putExtra("testIntent02", "1");
			intent5.setClass(this,LocationOverlayDemo.class);
			this.startActivity(intent5);

			break;
		case R.id.radio_button3:
			tabHost.setCurrentTabByTag(TAB_ITEM_3);
			break;
		case R.id.radio_button4:
			tabHost.setCurrentTabByTag(TAB_ITEM_4);
			break;
		case R.id.radio_button5:
			tabHost.setCurrentTabByTag(TAB_ITEM_5);
			break;
		default:
			break;
		}
	}

	@Override
	public void onStop() {

		super.onDestroy();
	}

	@Override
	public void onDestroy() {

		super.onDestroy();
	}

	private void showTips() {

		AlertDialog alertDialog = new AlertDialog.Builder(TabHostActivity.this)
				.setTitle("退出程序")

				.setMessage("是否退出程序")

				.setPositiveButton("确定", new DialogInterface.OnClickListener() {

					public void onClick(DialogInterface dialog, int which) {

						TabHostActivity.this.finish();

					}

				}).setNegativeButton("取消",

				new DialogInterface.OnClickListener() {

					public void onClick(DialogInterface dialog, int which) {

						return;

					}
				}).create(); // 创建对话框

		alertDialog.show(); // 显示对话框

	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {

		if (keyCode == KeyEvent.KEYCODE_BACK ) {

			this.showTips();

		}

		return false;

	}
	

}